from selenium import webdriver
import unittest,time
from day11_7_30.Page.Page import Page
from day11_7_30.Page.Page1 import Page1
from day11_7_30.JDBC.db import db
class Case(unittest.TestCase):
    def setUp(self):
        self.sql = db(host='10.59.9.12', user='root', password='yidong666', database='a3mall')
        self.driver = webdriver.Edge()

    def tearDown(self):
        time.sleep(10)
        self.driver.quit()

    def test_01_login(self):
        amount=self.sql.select("SELECT amount FROM mall_users WHERE username='19064013675'")
        print(amount[0][0])
        po = Page(self.driver)
        # 余额
        po.A3mall_log_01()
        self.assertEquals(float(po.yq21()), float(amount[0][0]))


    def test_02_search(self):
        amount = self.sql.select("SELECT amount FROM mall_users WHERE username='19064013675'")
        print(amount[0][0])
        po = Page1(self.driver)
        po.a3mall_search_01()
        self.assertEquals(float(po.yq21()), float(amount[0][0]))
        yq21 = po.yq21()

        # 搜索结果
        po.a3mall_search_02()
        self.assertEquals(po.yq5(), '搜索结果')
        yq6 = po.yq6()
        yq61 = yq6.replace('￥', '')
        print(yq61)
        po.a3mall_search_03()
        self.assertEquals(float(yq61),float(po.yq3()))
        po.a3mall_search_04()
        po.a3mall_search_05()
        po.a3mall_search_06()
        po.a3mall_search_07()
        yq4=po.yq4()
        y41=yq4.replace('+','')
        y7=po.yq7()
        po.a3mall_search_08()
        self.assertEquals(po.yq8(),'您的订单支付成功')
        sum=float(yq21)-float(yq61)*int(y7)-float(y41)
        print(sum)
        po.a3mall_search_09()
        self.assertEquals(float(po.yq9()),sum)


if __name__ == '__main__':
    unittest.main()